<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>店铺列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <!-- <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" /> -->
        
        <link rel="stylesheet" href="/static/layui/css/layui.css"  media="all">

        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script type="text/javascript" src="/static/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
<body>
    <div style="padding: 20px">
        <div class="demoTable">
            <div class="layui-inline">
                <input class="layui-input" name="name" id="name" autocomplete="off" placeholder="搜索商户名称">
            </div>
            <button class="layui-btn" id="seach">搜索</button>
        </div>
    
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
 
    <script type="text/html" id="barDemo">
        <!-- {{# if(d.status == '待审核'){}}
        <a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="back">驳回</a>
        {{# } }} -->

        <!-- {{# if(d.status != '待审核'){}} -->
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <!-- {{# } }} -->
        
    </script>

    <script>
        var page = 1;
        $(function(){
            if(window.location.href.includes('#!true=')){
                page = window.location.href.split('#!true=')[1];
            }
        })

        layui.use('table', function(){
            var table = layui.table,form = layui.form;

            function getList(){
                table.render({
                    elem: '#test'
                    ,url:'{:url("Shop/shop_data")}'
                    ,toolbar: true // 开启头部工具栏
                    ,defaultToolbar: ['filter']
                    ,title: '店铺信息表'
                    ,where: {
                        key: {
                            name: $('#name').val()
                        }
                    }
                    ,cols: [[
                        {field:'id', title:'ID', fixed: 'left', width: 80, sort: true}
                        ,{field:'cate_id', title:'商户分类', width: 150}
                        ,{field:'name', title:'商户名称', width: 150}
                        ,{field:'brief', title:'商户店铺简介', width: 150}
                        ,{field:'brief_apply', title:'商户申请简介', width: 150}
                        ,{field:'bond_max', title:'保证金', width: 100, sort: true}
                        ,{field:'shareholder_money', title:'股份份额', width: 120, sort: true}
                        ,{field:'shareholder_num', title:'股东人数', width: 120, sort: true}
                        ,{field:'address', title:'店铺地址', width: 150}
                        ,{field:'head_img', title:'门头照', width: 100}
                        ,{field:'license', title:'营业执照', width: 100}
                        ,{field:'is_frozen', title:'考核', templet: function(res){
                            return `<input type="checkbox" ${res.status == 1?'checked':''} name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status">`
                        }, width: 100}
                        ,{field:'status', title:'状态', width: 100}
                        ,{field:'start_time', title:'开业时间', width: 200, sort: true}
                        ,{field:'create_time', title:'创建时间', width: 200, sort: true}
                        ,{fixed: 'right', title:'操作', width: 120, toolbar: '#barDemo'}
                    ]]
                    ,page: {
                        curr: page,
                        hash: true
                    }
                });
            }

            getList()

            $("#seach").on('click',function(){
                getList()
            })
          
            // 监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;

                if(obj.event === 'del'){
                    layer.confirm('真的删除么', function(index){
                        $.post('{:url("Shop/shop_del")}',{
                            id: obj.data.id
                        },function(res){
                            if(res.code == 400){
                                layer.msg(res.msg, {icon: 2});
                            }else{
                                obj.del();
                                layer.msg(res.msg, {icon: 1});
                            }
                        })

                        layer.close(index);
                    });
                }else if(obj.event === 'pass'){
                    layer.confirm('确定要通过吗？', function(index){
                        $.post('{:url("Shop/shop_pass")}',{
                            id: obj.data.id
                        },function(res){
                            if(res.code == 400){
                                layer.msg(res.msg, {icon: 2});
                            }else{
                                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                    window.location.reload()
                                }, 1000);
                            }
                        })

                        layer.close(index);
                    });
                }else if(obj.event === 'back'){
                    layer.prompt({
                        formType: 2
                        ,title: data.name +'的申请驳回'
                    }, function(value, index){
                        //这里一般是发送修改的Ajax请求
                        $.post('{:url("Shop/shop_back")}',{
                            id: obj.data.id
                            , back_msg: value
                        },function(res){
                            if(res.code == 400){
                                layer.msg(res.msg, {icon: 2});
                            }else{
                                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                    // getList();
                                    window.location.reload()
                                }, 1000);
                            }
                        })

                        layer.close(index);
                    });
                }else if(obj.event === 'edit'){
                    window.location.href = "{:url('Shop/shop_edit')}?id=" + obj.data.id;
                }
            });

            // 启用禁用操作
            form.on('switch(status)', function(obj){
                let id = $(obj.elem).parents("tr").find("td[data-field='id'] div").text()
                $.post('{:url("Shop/setStatus")}',{id:id},function(res){
                    if(res.code == 400){
                        layer.msg(res.msg, {icon: 2});
                        setTimeout(() => {
                            window.location.reload()
                        }, 1000);
                    }else{
                        layer.msg(res.msg, {icon: 1});
                    }
                })
            });
        });
    </script>
</body>
</html>